package com.cxs.slidertest.component;

import com.cxs.slidertest.ResourceTable;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;
import ohos.app.Context;

public class Test extends ComponentContainer {

    private Context context;
    private Text text;
    public Test(Context context) {
        super(context);
        this.context = context;
        Component cptLayout = LayoutScatter.getInstance(context)
                .parse(ResourceTable.Layout_ability_test, null, false);
        text = (Text) cptLayout.findComponentById(ResourceTable.Id_ability_test_text);
        // 重要,将ability_test里的组件添加到Test组件的队列末尾
        addComponent(cptLayout);
    }

    public void changeText() {
        context.getUITaskDispatcher().delayDispatch(new Runnable() {
            @Override
            public void run() {
                text.setText("nihao");
            }
        }, 0);
    }
}